package com.example.zhaoyulu.yunzhiapp;

import android.content.Context;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

public class registActivity extends AppCompatActivity {

    public static class MyAdapter extends BaseAdapter {
        List<String> datas = new ArrayList<>();
        Context mContext;
        public MyAdapter(Context context) {
            this.mContext = context;
        }

        public void setDatas(List<String> datas) {
            this.datas = datas;
            notifyDataSetChanged();
        }

        @Override
        public int getCount() {
            return datas==null?0:datas.size();
        }

        @Override
        public Object getItem(int position) {
            return datas==null?null:datas.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHodler hodler = null;
            if (convertView == null) {
                hodler = new ViewHodler();
                convertView = LayoutInflater.from(mContext).inflate(R.layout.itemregist, null);
                hodler.mTextView = (TextView) convertView.findViewById(R.id.regist_tv12222);
                convertView.setTag(hodler);
            } else {
                hodler = (ViewHodler) convertView.getTag();
            }

            hodler.mTextView.setText(datas.get(position));

            return convertView;
        }

        private static class ViewHodler{
            TextView mTextView;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_regist);
        Button login_regist=findViewById(R.id.login_regist);

        final List<String> datas = new ArrayList<>();
        datas.add("数学");
        datas.add("英语");
        datas.add("计算机");

        MyAdapter adapter = new MyAdapter(this);

        Spinner spinner1=findViewById(R.id.spinner1);
        spinner1.setAdapter(adapter);

        Spinner spinner2=findViewById(R.id.spinner2);
        spinner2.setAdapter(adapter);

        Spinner spinner3=findViewById(R.id.spinner3);
        spinner3.setAdapter(adapter);

        adapter.setDatas(datas);

        login_regist.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
    }
}
